<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="system_public::header"></th:block>
</head>
<body>
	<table id="list"></table>
	<div id="addOrUpdateDialog" style="display:none;">
		<form method="post">
			<table class="addform">
				<tr>
					<td class="title" colspan="2"></td>
				</tr>
				<tr>
					<td class="label">ID</td>
					<td class="input">
						<input type="text" name="id">
					</td>
				</tr>
				<tr>
					<td class="label">用户类别名称</td>
					<td class="input">
						<input type="text" name="typename">
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div id="loginUserManagerTreeDialog" style="display:none;">
		<ul id="tree" class="easyui-tree" data-options="checkbox:true"></ul>
	</div>
	<th:block th:include="system_public::footer"></th:block>
	<th:block th:include="system_public::jsfile"></th:block>
	<script th:inline="none">
	$(function(){
		var $list = $('#list');
		var $addOrUpdateDialog = $('#addOrUpdateDialog');
		var $addOrUpdateDialog_form = $addOrUpdateDialog.children('form');
		var $loginUserManagerTreeDialog = $('#loginUserManagerTreeDialog');
		var $loginUserManagerTreeDialog_tree = $loginUserManagerTreeDialog.find('#tree');
		$list.datagrid({
			title : '用户类别列表',
			fit : true,
			url : pageurl+'/system/loginusertype/index',
			cls : 'list_padding',
			singleSelect : true,
			rownumbers : true,
			columns : [[{
				title : 'ID',
				field : 'id',
				width : 60
			},{
				title : '类别名称',
				field : 'typename',
				width : 150
			}]],
			toolbar : [{
				text : '刷新列表',
				iconCls : 'icon-reload',
				handler : function() {
					$list.datagrid("reload");
				}
			},'-',{
				text : '增加',
				iconCls : 'icon-add',
				handler : function() {
					$addOrUpdateDialog.dialog("open");
					$addOrUpdateDialog_form.find('td.title').text("增加新用户类别");
					$addOrUpdateDialog_form.attr("action", pageurl+"/system/loginusertype/add");
					$addOrUpdateDialog_form.find('input[name=id]').prop('readonly',false);
				}
			},'-',{
				text : '修改',
				iconCls : 'icon-edit',
				handler : function() {
					var row = $list.datagrid("getSelected");
					if(row) {
						$addOrUpdateDialog.dialog("open");
						$addOrUpdateDialog_form.find('td.title').text("修改"+row.typename+"用户类别");
						$addOrUpdateDialog_form.attr("action", pageurl+"/system/loginusertype/update");
						$addOrUpdateDialog_form.form("load", row);
					} else {
						$.messager.alert('系统提示','请先选择一个用户类别','info');
					}
				}
			},'-',{
				text : '删除',
				iconCls : 'icon-remove',
				handler : function() {
					var row = $list.datagrid("getSelected");
					if(row) {
						$.messager.confirm('删除用户类别提示','您是否要删除'+row.typename+'用户类别吗?',function(r){
							if(r) {
								$.post(pageurl+'/system/loginusertype/delete',{id:row.id},function(result){
									if(result.success) {
										$list.datagrid("reload");
										$.messager.alert('系统提示','删除成功','info');
									} else {
										$.messager.alert('系统提示',result.message,'warning');
									}
								},'json');
							}
						});
					} else {
						$.messager.alert('系统提示','请先选择一个用户类别','info');
					}
				}
			},'-',{
				text : '系统功能分配',
				iconCls : 'icon-edit',
				handler : function() {
					var row = $list.datagrid("getSelected");
					if(row) {
						$loginUserManagerTreeDialog.dialog('open');
						$.post(pageurl+'/system/loginusertype/get_user_type_manager_tree',{
							usertypeid : row.id
						},function(result){
							$loginUserManagerTreeDialog_tree.tree('loadData',result);
						},'json');
					} else {
						$.messager.alert('系统提示','请先选择一个用户类别','info');
					}
				}
			}]
		});
		$addOrUpdateDialog.show().dialog({
			title : '用户类别',
			iconCls : 'icon-save',
			modal : true,
			closed : true,
			width : 400,
			height : 250,
			buttons : [{
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					$addOrUpdateDialog_form.submit();
				}
			},{
				text : '返回',
				iconCls : 'icon-back',
				handler : function() {
					$addOrUpdateDialog.dialog("close");
				}
			}],
			onClose : function() {
				$addOrUpdateDialog_form.form("reset");
				$addOrUpdateDialog_form.find('input[name=id]').prop('readonly',true);
			}
		});
		$addOrUpdateDialog_form.form({
			success : function(data) {
				var obj = $.parseJSON(data);
				if(obj.success) {
					$.messager.alert('系统提示','操作成功','info');
					$addOrUpdateDialog.dialog("close");
					$list.datagrid("reload");
				} else {
					alert(obj.message);
				}
			},
			onLoadError : function(error) {
				alert(error);
			}
		});
		$loginUserManagerTreeDialog.show().dialog({
			title : '用户权限分配',
			iconCls : 'icon-edit',
			modal : true,
			closed : true,
			width : 350,
			height : 350,
			onClose : function() {
				$loginUserManagerTreeDialog_tree.tree("loadData",[]);
			},
			buttons : [{
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var nodes = $loginUserManagerTreeDialog_tree.tree('getChecked',['checked','indeterminate']);
					var array = [];
					$.each(nodes, function(index, node){
						array.push(node.id);
					});
					var str = array.join(',');
					var row = $list.datagrid('getSelected');
					$.post(pageurl+'/system/loginusertype/updateusertypenav',{
						loginUserTypeId : row.id,
						navstr : str
					},function(result){
						if(result) {
							$.messager.alert('系统提示','保存成功','info');
							$loginUserManagerTreeDialog.dialog("close");
						} else {
							$.messager.alert('系统提示','保存失败','warning');
						}
					},'json');
				}
			},{
				text : '返回',
				iconCls : 'icon-back',
				handler : function() {
					$loginUserManagerTreeDialog.dialog("close");
				}
			}]
		});
	});
	</script>
</body>
</html>